# coding:utf-8
import time

from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from sql_foreign_models import *

engine = create_engine("sqlite:///test.db")
Session_class = sessionmaker(bind=engine)
session = Session_class()




while (1):
    # 查询company表
    company_obj = session.query(Company).filter_by(name="Nokia").first()
    # 通过phone表关联的relationship的字段"backref="phone_of_company"",查询phone表数据
    value = company_obj.phone_of_company[0].id, company_obj.phone_of_company[0].model, company_obj.phone_of_company[
        0].price, company_obj.phone_of_company[0].company_name
    print(value)
    time.sleep(0.5)
